<!--   [PAGE]] : 工单明细
       @Author  : ljq
       @Created : 2025/10/12
 -->
<template>
  <div class="app-container">
    <!-- ------------------------ START: 查询框 -------------------------->
    <el-form class="query" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="项目">
        <el-input  v-model="queryParams.params.projectNameLike"  placeholder="请输入项目"  clearable  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="工人">
        <select-user v-model="queryParams.params.userIdList" placeholder="请选择工人"/>
      </el-form-item>
      <el-form-item label="银行卡">
        <select-bank-card v-model="queryParams.params.bankCardIdList" placeholder="请选择银行卡"/>
      </el-form-item>
      <el-form-item label="日期">
        <el-input  v-model="queryParams.params.workDateLike"  placeholder="请输入日期"  clearable  @keyup.enter.native="handleQuery"/>
      </el-form-item>
<!--      <el-form-item label="上班时间区间">-->
<!--        <el-input  v-model="queryParams.params.planWorkTimeRangeLike"  placeholder="请输入上班时间区间"  clearable  @keyup.enter.native="handleQuery"/>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="上班时间">-->
<!--        <el-date-picker v-model="queryParams.params.realWorkStartAtRange"  style="width: 240px"  value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"/>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="下班时间">-->
<!--        <el-date-picker v-model="queryParams.params.realWorkEndAtRange"  style="width: 240px"  value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"/>-->
<!--      </el-form-item>-->

<!--      <el-form-item label="备注">-->
<!--        <el-input  v-model="queryParams.params.commentLike"  placeholder="请输入备注"  clearable  @keyup.enter.native="handleQuery"/>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="类型">-->
<!--        <el-select v-model="queryParams.type" placeholder="类型" filterable clearable>-->
<!--          <el-option  v-for="dict in dict.type.字典v" :key="dict.value" :label="dict.label" :value="dict.value"/>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item label="状态">
        <el-select v-model="queryParams.status" placeholder="状态" filterable clearable>
          <el-option  v-for="dict in dict.type.business_work_order_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="审批人">
        <select-user v-model="queryParams.params.approvalByList" placeholder="请选择审批人"/>
      </el-form-item>
      <el-form-item label="工种">
        <el-input  v-model="queryParams.params.workTypeLike"  placeholder="请输入工种"  clearable  @keyup.enter.native="handleQuery"/>
      </el-form-item>

      <el-form-item class="option">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- ------------------------- END: 查询框 --------------------------->

    <!-- ---------------------- START: 主数据区域------------------------->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-back" size="mini" @click="toBack">返回</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="[`${permi}:add`]">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="[`${permi}:remove`]">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"/>
    </el-row>


    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center"/>
      <el-table-column label="编号" align="center" prop="id" v-if="columns[0].visible"/>
      <el-table-column label="项目" align="center" prop="project.name" v-if="columns[1].visible"/>
      <el-table-column label="工人" align="center" prop="userId" v-if="columns[2].visible">
        <template slot-scope="scope">
          <select-user :isCol="true"  :value="scope.row.userId"/>
        </template>
      </el-table-column>
      <el-table-column label="银行卡" align="center" prop="bankCard.cardId" v-if="columns[3].visible"/>
      <el-table-column label="工作日期" align="center" prop="workDate" v-if="columns[10].visible"/>
      <el-table-column label="工作时间" align="center" prop="planWorkTimeRange" v-if="columns[4].visible"/>
      <el-table-column label="计划工时" align="center" prop="planHour" v-if="columns[7].visible"/>
      <el-table-column label="上班时间" align="center" prop="realWorkStartAt" v-if="columns[5].visible"/>
      <el-table-column label="下班时间" align="center" prop="realWorkEndAt" v-if="columns[6].visible"/>
      <el-table-column label="实际工时" align="center" prop="realHour" v-if="columns[8].visible"/>
      <el-table-column label="备注" align="center" prop="comment" v-if="columns[9].visible"/>
      <el-table-column label="状态" align="center" prop="status" v-if="columns[11].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.business_work_order_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="审批人" align="center" prop="approvalBy" v-if="columns[12].visible">
        <template slot-scope="scope">
          <select-user :isCol="true"  :value="scope.row.approvalBy"/>
        </template>
      </el-table-column>
      <el-table-column label="驳回原因" align="center" prop="approvalComment" v-if="columns[13].visible"/>
      <el-table-column label="时薪" align="center" prop="hourlyWage" v-if="columns[14].visible"/>
      <el-table-column label="工种" align="center" prop="workType" v-if="columns[15].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.business_work_type" :value="scope.row.workType"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[16].visible"/>
      <el-table-column label="创建者"   align="center" prop="createBy"   v-if="columns[17].visible"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" v-if="columns[18].visible"/>
      <el-table-column label="更新者"   align="center" prop="updateBy"   v-if="columns[19].visible"/>
      <!-- 操作列 -->
      <operation-column :permi="permi" @edit="handleUpdate" @delete="handleDelete"/>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
    <!-- ---------------------- END: 主数据区域 ------------------------>

    <!-- ------------------------ START: 弹出框 -------------------------->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目" prop="projectId">
              <el-input v-model="form.projectId" placeholder="请输入项目"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工人" prop="userId">
              <select-user v-model="form.userId" placeholder="请选择工人"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行卡" prop="bankCardId">
              <select-bank-card v-model="form.bankCardId" placeholder="请选择银行卡"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上班时间区间" prop="planWorkTimeRange">
              <el-input v-model="form.planWorkTimeRange" placeholder="请输入上班时间区间"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上班时间" prop="realWorkStartAt">
              <el-date-picker clearable v-model="form.realWorkStartAt" type="date"  value-format="yyyy-MM-dd HH:mm:ss" placeholder="请输入上班时间"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下班时间" prop="realWorkEndAt">
              <el-date-picker clearable v-model="form.realWorkEndAt" type="date"  value-format="yyyy-MM-dd HH:mm:ss" placeholder="请输入下班时间"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计划工时" prop="planHour">
              <el-input v-model="form.planHour" placeholder="请输入计划工时"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际工时" prop="realHour">
              <el-input v-model="form.realHour" placeholder="请输入实际工时"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="comment">
              <el-input v-model="form.comment" placeholder="请输入备注"/>
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item label="类型" prop="type">-->
<!--              <el-select v-model="form.type" placeholder="类型"  filterable  clearable>-->
<!--                <el-option  v-for="dict in dict.type.字典v" :key="dict.value" :label="dict.label" :value="dict.value"/>-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-select v-model="form.status" placeholder="状态"  filterable  clearable>
                <el-option  v-for="dict in dict.type.business_work_order_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审批人" prop="approvalBy">
              <select-user v-model="form.approvalBy" placeholder="请选择审批人"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="驳回原因" prop="approvalComment">
              <el-input v-model="form.approvalComment" placeholder="请输入驳回原因"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="时薪" prop="hourlyWage">
              <el-input v-model="form.hourlyWage" placeholder="请输入时薪"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工种" prop="workType">
              <el-select v-model="form.workType" placeholder="工种"  filterable  clearable>
                <el-option  v-for="dict in dict.type.business_work_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- ------------------------ END: 弹出框 -------------------------->
  </div>
</template>
<script>
import {listProjectDetail, getProjectDetail, addProjectDetail, updateProjectDetail, delProjectDetail} from "@/api/business/projectDetail";
import {initData,  baseMethods} from "@/utils/basePage";


let baseData = initData();
baseData.baseTitle = "";
baseData.form.status = '1';


export default {
  name: "ProjectDetail",
  dicts: ['business_work_type','business_work_order_status'],
  components: { },
  data() {
    return {
      ...baseData,
      permi: 'business:detail',
      // 列信息
      columns: [
        { key: 0, label: `编号`, visible: false },
        { key: 1, label: `项目`, visible: true },
        { key: 2, label: `工人`, visible: true },
        { key: 3, label: `银行卡`, visible: true },
        { key: 4, label: `上班时间区间`, visible: true },
        { key: 5, label: `上班时间`, visible: true },
        { key: 6, label: `下班时间`, visible: true },
        { key: 7, label: `计划工时`, visible: true },
        { key: 8, label: `实际工时`, visible: true },
        { key: 9, label: `备注`, visible: true },
        { key: 10, label: `日期`, visible: true },
        { key: 11, label: `状态`, visible: true },
        { key: 12, label: `审批人`, visible: true },
        { key: 13, label: `驳回原因`, visible: true },
        { key: 14, label: `时薪`, visible: true },
        { key: 15, label: `工种`, visible: true },
        { key: 16, label: `创建时间`, visible: false },
        { key: 17, label: `创建者`,   visible: false },
        { key: 18, label: `更新时间`, visible: false },
        { key: 19, label: `创建者`,   visible: false },
      ],
      // 表单校验
      rules:{
        projectId:[{ required: true, message: "项目不能为空", trigger: "blur" }],
        userId:[{ required: true, message: "工人不能为空", trigger: "blur" }],
        bankCardId:[{ required: true, message: "银行卡不能为空", trigger: "blur" }],
        planWorkTimeRange:[{ required: true, message: "上班时间区间不能为空", trigger: "blur" }],
        realWorkStartAt:[{ required: true, message: "上班时间不能为空", trigger: "blur" }],
        realWorkEndAt:[{ required: true, message: "下班时间不能为空", trigger: "blur" }],
        planHour:[{ required: true, message: "计划工时不能为空", trigger: "blur" }],
        realHour:[{ required: true, message: "实际工时不能为空", trigger: "blur" }],
        hourlyWage:[{ required: true, message: "时薪不能为空", trigger: "blur" }],
        delFlag:[{ required: true, message: "删除标志不能为空", trigger: "blur" }],
      }
    };
  },
  created() {
    this.routeParams = this.$route.query || {};
    this.defaultForm.projectId = this.routeParams.projectId;
    // this.defaultForm.type = '0';

    this.queryParams.projectId = this.routeParams.projectId;
    // this.queryParams.type = '0';

    this.getList();
  },
  methods: {
    ...baseMethods(listProjectDetail, getProjectDetail, addProjectDetail, updateProjectDetail, delProjectDetail),

    toBack() {
      this.$router.back()
    },

  }
};
</script>
